package cc.angis.xiugallery.provider;

import java.util.List;

import android.content.Context;
import cc.angis.xiugallery.data.UserAccount;
import cc.angis.xiugallery.db.TableConstants;
import cc.angis.xiugallery.db.UserAccountDBHelper;

public class UserAccountProvider {
	
	private Context context;
	
	private List<UserAccount> userAccounts;
	
	public UserAccountProvider(Context context){
		this.context = context;
	}
	
	public void initSource(){
		UserAccountDBHelper dhHelper = new UserAccountDBHelper(context, TableConstants.TABLE_USER_ACCOUNT);
		try{
			userAccounts = dhHelper.getAllUserAccounts();
		}catch(Exception e){
			
		}finally{
			dhHelper.closeDB();
		}
	}

	public List<UserAccount> getUserAccounts() {
		return userAccounts;
	}

	public void setUserAccounts(List<UserAccount> userAccounts) {
		this.userAccounts = userAccounts;
	}
	
	public boolean hasUserAccount(int type){
		for (UserAccount account : userAccounts){
			if (account.getType() == type)
				return true;
		}
		return false;
	}
	
	public UserAccount getUserAccount(int type){
		for (UserAccount account : userAccounts){
			if (account.getType() == type)
				return account;
		}
		return null;
	}

}
